package com.linkgie.galaxyframework.utils.json;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

public class ProxySerializer<T> extends StdSerializer<T>{

 	private static final long serialVersionUID = 5585118573814972407L;

	protected ProxySerializer(Class<T> valueType) {
		super(valueType);
	}

	@Override
	public void serialize(T value, JsonGenerator gen, SerializerProvider provider) throws IOException {
		if (value instanceof JsonProxy) {
			JsonNode jsonValue = ((JsonProxy) value).jsonValue();
			gen.writeTree(jsonValue);
		}
	}

}
